<%--
    Document   : index
    Created on : 01.05.2009, 22:15:56
    Author     : Vladimir
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="ru.prjpeople.model.Position"%>
<%@page import="java.util.Collection"%>
<%@page import="ru.prjpeople.model.Person"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%Collection<Person> persons = (Collection<Person>)request.getAttribute("persons");%>
        <%if(persons != null && persons.size() > 0) {%>
            <form method="post" action="delete">
                <table cellpadding="2" cellspacing="2">
                    <caption>Список</caption>
                    <tr>
                        <th>Ф.И.О.</th>
                        <th>Должность</th>
                        <th>Удалить</th>
                    </tr>
                    <%--список--%>
                    <%for(Person p : persons) {%>
                    <tr>
                        <td>
                            <a href="editperson?personID=<%=p.getKey()%>">
                                <%=p.getLastName() + " "%>
                                <%=p.getName() + " "%>
                                <%=p.getPatronymic()%>
                            </a>
                        </td>
                        <td><%=p.getPosition().getTitle()%></td>
                        <td align="center"> <!-- isDelete - хорошее имя, молодец.-->
                            <input type="checkbox" name="isDelete" value="<%=p.getKey()%>"/>
                        </td>
                    </tr>
                    <%}%>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                        <td>
                            <input type="submit" name="delete" value="удалить"/>
                        </td>
                    </tr>
                </table>
            </form>
        <%}%>
        <form method="post" action="saveperson">
            <table>
                <tr>
                    <td>Фамилия:</td> <!-- за реквест скоуп респект и уважуха.-->
                    <td><input type="text" name="lastName" value="${requestScope.lastName}"/></td>
                </tr>
                <tr>
                    <td>Имя:</td>
                    <td><input type="text" name="name" value="${requestScope.name}"/></td>
                </tr>
                <tr>
                    <td>Отчество:</td>
                    <td><input type="text" name="patronymic" value="${requestScope.patronymic}"/></td>
                </tr>
                <tr>
                    <td>Должность:</td>
                    <td>
                        <select name="position">
                            <option value="0">
                                --выберите должность
                            </option>
                            <% for(Position p: Position.values()) { %>
                                <option value="<%=p.name()%>"
                                <%if(p.name().equals((String)request.getAttribute("position"))) {%>
                                    selected
                                <%}%>
                                >
                                    
                                <%=p.getTitle()%>
                                </option>
                            <% } %>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                        <input type="hidden" name ="personID" value="0" />
                    </td>
                    <td><input type="submit" value="добавить"></td>
                </tr>
            </table>
            <% String msg = (String) request.getAttribute("errorMessage");%>
            <% if(msg != null) {%>
                <p>
                    <%=msg%>
                </p>
            <%}%>
        </form>
    </body>
</html>
